<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>

<div id="packed_window">
<?php foreach ($block->getPackages() as $packageId => $package): ?>
    <?php $package = new \Magento\Framework\DataObject($package) ?>
    <?php $params = new \Magento\Framework\DataObject($package->getParams()) ?>
    <section class="admin__page-section">
        <div class="admin__page-section-title">
            <span class="title"><?php /* @escapeNotVerified */ echo __('Package') . ' ' . $packageId ?></span>
        </div>
        <div class="admin__page-section-content">
            <div class="row row-gutter">
                <div class="col-m-4">
                    <table class="admin__table-secondary">
                        <tbody>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Type') ?></th>
                                <td><?php /* @escapeNotVerified */ echo $block->getContainerTypeByCode($params->getContainer()) ?></td>
                            </tr>
                            <tr>
                            <?php if ($block->displayCustomsValue()): ?>
                                <th><?php /* @escapeNotVerified */ echo __('Customs Value') ?></th>
                                <td><?php /* @escapeNotVerified */ echo $block->displayCustomsPrice($params->getCustomsValue()) ?></td>
                            <?php else: ?>
                                <th><?php /* @escapeNotVerified */ echo __('Total Weight') ?></th>
                                <td><?php /* @escapeNotVerified */ echo $params->getWeight() . ' ' . $this->helper('Magento\Shipping\Helper\Carrier')->getMeasureWeightName($params->getWeightUnits()) ?></td>
                            <?php endif; ?>
                            </tr>
                        <?php if ($params->getSize()): ?>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Size') ?></th>
                                <td><?php /* @escapeNotVerified */ echo ucfirst(strtolower($params->getSize())) ?></td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="col-m-4">
                    <table class="admin__table-secondary">
                        <tbody>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Length') ?></th>
                                <td>
                                <?php if ($params->getLength() != null): ?>
                                    <?php /* @escapeNotVerified */ echo $params->getLength() . ' ' . $this->helper('Magento\Shipping\Helper\Carrier')->getMeasureDimensionName($params->getDimensionUnits()) ?>
                                <?php else: ?>
                                    --
                                <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Width') ?></th>
                                <td>
                                <?php if ($params->getWidth() != null): ?>
                                    <?php /* @escapeNotVerified */ echo $params->getWidth() . ' ' . $this->helper('Magento\Shipping\Helper\Carrier')->getMeasureDimensionName($params->getDimensionUnits()) ?>
                                <?php else: ?>
                                    --
                                <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Height') ?></th>
                                <td>
                                <?php if ($params->getHeight() != null): ?>
                                    <?php /* @escapeNotVerified */ echo $params->getHeight() . ' ' . $this->helper('Magento\Shipping\Helper\Carrier')->getMeasureDimensionName($params->getDimensionUnits()) ?>
                                <?php else: ?>
                                    --
                                <?php endif; ?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="col-m-4">
                    <table class="admin__table-secondary">
                        <tbody>
                        <?php if ($params->getDeliveryConfirmation() != null): ?>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Signature Confirmation') ?></th>
                                <td><?php /* @escapeNotVerified */ echo $block->getDeliveryConfirmationTypeByCode($params->getDeliveryConfirmation()) ?></td>
                            </tr>
                        <?php endif; ?>
                        <?php if ($params->getContentType() != null): ?>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Contents') ?></th>
                                <?php if ($params->getContentType() == 'OTHER'): ?>
                                    <td><?php echo $block->escapeHtml($params->getContentTypeOther()) ?></td>
                                <?php else: ?>
                                    <td><?php /* @escapeNotVerified */ echo $block->getContentTypeByCode($params->getContentType()) ?></td>
                                <?php endif; ?>
                            </tr>
                        <?php endif; ?>
                        <?php if ($params->getGirth()): ?>
                            <tr>
                                <th><?php /* @escapeNotVerified */ echo __('Girth') ?></th>
                                <td><?php /* @escapeNotVerified */ echo $params->getGirth() . ' ' . $this->helper('Magento\Shipping\Helper\Carrier')->getMeasureDimensionName($params->getGirthDimensionUnits()) ?></td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="admin__page-section-item-title">
            <span class="title"><?php /* @escapeNotVerified */ echo __('Items in the Package') ?></span>
        </div>
        <div class="admin__table-wrapper">
            <table class="data-table admin__table-primary">
                <thead>
                <tr class="headings">
                    <th class="col-product"><span><?php /* @escapeNotVerified */ echo __('Product') ?></span></th>
                    <th class="col-weight"><span><?php /* @escapeNotVerified */ echo __('Weight') ?></span></th>
                    <?php if ($block->displayCustomsValue()): ?>
                        <th class="col-custom"><span><?php /* @escapeNotVerified */ echo __('Customs Value') ?></span></th>
                    <?php endif; ?>
                    <th class="col-qty"><span><?php /* @escapeNotVerified */ echo __('Qty Ordered') ?></span></th>
                    <th class="col-qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></th>
                </tr>
                </thead>
                <tbody id="">
                <?php foreach ($package->getItems() as $itemId => $item) : ?>
                    <?php $item = new \Magento\Framework\DataObject($item) ?>
                    <tr title="#" id="">
                        <td class="col-product">
                            <?php /* @escapeNotVerified */ echo $item->getName(); ?>
                        </td>
                        <td class="col-weight">
                            <?php /* @escapeNotVerified */ echo $item->getWeight(); ?>
                        </td>
                        <?php if ($block->displayCustomsValue()): ?>
                            <td class="col-custom"><?php /* @escapeNotVerified */ echo $block->displayCustomsPrice($item->getCustomsValue()) ?></td>
                        <?php endif; ?>
                        <td class="col-qty">
                            <?php /* @escapeNotVerified */ echo $block->getQtyOrderedItem($item->getOrderItemId()); ?>
                        </td>
                        <td class="col-qty">
                            <?php /* @escapeNotVerified */ echo $item->getQty()*1; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </section>
<?php endforeach; ?>
</div>
<script>
    function showPackedWindow() {
        jQuery('#packed_window').modal('openModal');
    }
</script>

<script type="text/x-magento-init">
    {
        "#packed_window": {
            "Magento_Shipping/js/packages":{
                "type":"slide",
                "title":"<?= /* @escapeNotVerified */  __('Packages') ?>",
                "url": "<?= /* @escapeNotVerified */ $block->getPrintButton(); ?>"
            }
        }
    }
</script>
